package com.sws.web.controller.prompts;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sws.common.annotation.Log;
import com.sws.common.core.controller.BaseController;
import com.sws.common.core.domain.AjaxResult;
import com.sws.common.enums.BusinessType;
import com.sws.prompts.domain.AiPrompts;
import com.sws.prompts.service.IAiPromptsService;
import com.sws.common.utils.poi.ExcelUtil;
import com.sws.common.core.page.TableDataInfo;

/**
 * AI提示词管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-03
 */
@RestController
@RequestMapping("/ry/prompts/prompts")
public class AiPromptsController extends BaseController {
    @Autowired
    private IAiPromptsService aiPromptsService;

    /**
     * 查询AI提示词管理列表
     */
    @PreAuthorize("@ss.hasPermi('ry/prompts:prompts:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiPrompts aiPrompts) {
        startPage();
        List<AiPrompts> list = aiPromptsService.selectAiPromptsList(aiPrompts);
        return getDataTable(list);
    }

    /**
     * 导出AI提示词管理列表
     */
    @PreAuthorize("@ss.hasPermi('ry/prompts:prompts:export')")
    @Log(title = "AI提示词管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiPrompts aiPrompts) {
        List<AiPrompts> list = aiPromptsService.selectAiPromptsList(aiPrompts);
        ExcelUtil<AiPrompts> util = new ExcelUtil<AiPrompts>(AiPrompts.class);
        util.exportExcel(response, list, "AI提示词管理数据");
    }

    /**
     * 获取AI提示词管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ry/prompts:prompts:query')")
    @GetMapping(value = "/{promptId}")
    public AjaxResult getInfo(@PathVariable("promptId") Long promptId) {
        return success(aiPromptsService.selectAiPromptsByPromptId(promptId));
    }

    /**
     * 新增AI提示词管理
     */
    @PreAuthorize("@ss.hasPermi('ry/prompts:prompts:add')")
    @Log(title = "AI提示词管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiPrompts aiPrompts) {
        return toAjax(aiPromptsService.insertAiPrompts(aiPrompts));
    }

    /**
     * 修改AI提示词管理
     */
    @PreAuthorize("@ss.hasPermi('ry/prompts:prompts:edit')")
    @Log(title = "AI提示词管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiPrompts aiPrompts) {
        return toAjax(aiPromptsService.updateAiPrompts(aiPrompts));
    }

    /**
     * 删除AI提示词管理
     */
    @PreAuthorize("@ss.hasPermi('ry/prompts:prompts:remove')")
    @Log(title = "AI提示词管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{promptIds}")
    public AjaxResult remove(@PathVariable Long[] promptIds) {
        return toAjax(aiPromptsService.deleteAiPromptsByPromptIds(promptIds));
    }
}
